//
//  MineApi.swift
//  MT
//
//  Created by M on 2019/12/25.
//  Copyright © 2019 张强. All rights reserved.
//

import UIKit
import Moya
import DeviceKit
import SwiftyRSA
import Security

import Result

enum MineApi {

    /// 获取个人信息
    case info(_ username: String?)
    
    /// 获取动态发布列表
    case list(_ curPage: Int, _ username: String?)
    
    /// 修改用户信息
    case userInfoModify(_ params: [String: Any])
    
    /// 用户照片视频保存
    case userMediaInfoSave(_ params: [String: Any])
    
    /// 用户照片视频删除
    case userMediaInfoDelete(_ id: Int)
    
    /// 用户照片视频查询
    case userMediaInfoQueryList
    
    /// Vip 申请
    case vipApply
    ///我的礼物
    case receiveStatics
    ///我的账户
    case sendStatics
    
    ///礼物接收记录
    case giftReceiveList(_ curPage: Int)
    
    ///礼物发放记录
    case giftSendList(_ curPage: Int)
    
    ///红包发放记录
    case redPacketSendList(_ curPage: Int)
    
    ///红包接受记录
    case redPacketReceiveList(_ curPage: Int)
    
    ///充值钻石记录
    case rechargeList(_ curPage: Int)
    
    ///提现记录
    case withdrawList(_ curPage: Int)
    ///实名认证
    case verification(_ params: [String: Any])
    
    ///提现奖励规则
    case withdrawRule
    
    ///添加提现账号
    case addAccount(_ params: [String: Any])
    
    ///邀请好友列表
    case inviteList(_ curPage: Int)
    
    ///企业认证信息申请
    case companyApply(_ params: [String: Any])
    ///个人认证信息申请
    case personalApply(_ params: [String: Any])

    ///用户认证汇总
    case applySummary
}


// MARK: ------------------ Api 参数 ----------------------
extension MineApi: MTTargetType {

    /// 请求头
    public var headers: [String : String]? {
        guard let accessToken = UserDefaults.MTUserCenter.token.storedString else { return nil }
        return ["Access-Token": accessToken]
    }
    
    /// 基路径
    public var baseURL: URL {
        return URL(string: AuthServerBaseUrl)!
//        switch self {
//        case .inviteList:
//            return URL(string:"https://www.fastmock.site/mock/edfb229f1d5c564a20a2f6176fe663be/invitelist")!
//        default:
//            return URL(string: AuthServerBaseUrl)!
//        }
        
    }
    
    /// 路径
    public var path: String {
        switch self {
        case .info:
            return "/user-cent/info"
            
        case .list:
            return "/user-cent/list"
            
        case .userInfoModify:
            return "/user/modify"
            
        case .userMediaInfoSave:
            return "userImgVedio/save"
            
        case .userMediaInfoDelete:
            return "userImgVedio/delete"
            
        case .userMediaInfoQueryList:
            return "userImgVedio/queryList"
            
        case .vipApply:
            return "/user/vip-apply"
        case .receiveStatics:
            return "/user-cent/receive-statics"
        case .sendStatics:
            return "/user-cent/send-statics"
        case .giftSendList:
            return "/gift/gift-send-list"
        case .giftReceiveList:
            return "/gift/gift-receive-list"
        case .redPacketSendList:
            return "/redpacketPull/list"
        case .redPacketReceiveList:
            return "/redpacketPull/list"
        case .rechargeList:
            return "/purchase/recharge-list"
        case .withdrawList:
            return "/withdraw/list"
        case .verification:
            return "/user-cent/apply-verification"
        case .withdrawRule:
            return "/withdraw/rule"
        case.addAccount:
            return "/withdraw/add-account"
        case .inviteList:
            return "/userFriend/invite-list"
        case .applySummary:
            return "/userCertification/summary"
        case .companyApply:
            return "/userCertification/company-apply"
        case .personalApply:
            return "/userCertification/person-apply"
        }
        
    }
    
    /// 请求方法
    public var method: Moya.Method {
        switch self {
        default:        return .post
        }
    }
    
    /// 参数
    var params: [String: Any]? {
        
        switch self {
            
        case let .info(username):
            if let username = username {
                return ["userName": username]
            }
            return nil
            
        case let .list(curPage, username):
            if let username = username {
                return ["curPage":curPage,
                        "pageSize": 10,
                        "userName": username]
            }
            return ["curPage":curPage,
                    "pageSize": 10]
            
        case let .userInfoModify(params):
            return params
            
        case let .userMediaInfoSave(params):
            return params
            
        case let .userMediaInfoDelete(id):
            return ["id": id]
            
        case .userMediaInfoQueryList:
            return nil
            
        case .vipApply, .receiveStatics,.sendStatics:
            return nil
        case let .giftReceiveList(curPage):
            return ["curPage":curPage,
                    "pageSize":10]
        case let .giftSendList(curPage):
            return ["curPage":curPage,
                    "pageSize":10]
        case let .redPacketReceiveList(curPage):
            return ["curPage":curPage,
                    "pageSize":10,
                    "type":1]
        case let .redPacketSendList(curPage):
            return ["curPage":curPage,
                    "pageSize":10,
                    "type":2]
        case let .rechargeList(curPage):
            return ["curPage":curPage,
                    "pageSize":10]
        case let .withdrawList(curPage):
            return ["curPage":curPage,
                    "pageSize":10]
        case let .verification(params):
                return params
        case .withdrawRule:
            return nil
        case let .addAccount(params):
            return params
        case let .inviteList(curPage):
                return ["curPage":curPage,
                        "pageSize":10]
        case .applySummary:
            return nil
        case let .companyApply(params):
            return params
        case let .personalApply(params):
                return params
        }
        
    }
    
}

